define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'live/index' + location.search,
                    add_url: 'live/add',
                    edit_url: 'live/edit',
                    del_url: 'live/del',
                    multi_url: 'live/multi',
                    table: 'live',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        //{field: 'admin_id', title: __('Admin_id')},
                        {field: 'title', title: __('Title')},
                        {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        //{field: 'desc', title: __('Desc')},
                        {field: 'views', title: __('Views')},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        {field: 'state', title: __('State'), searchList: {"normal":__('State normal'),"hidden":__('State hidden')}, formatter: Table.api.formatter.normal},
                        //{field: 'live_url', title: __('Live_url'), formatter: Table.api.formatter.url},
                        {field: 'live_views', title: __('Live_views')},
                        //{field: 'recorded_url', title: __('Recorded_url'), formatter: Table.api.formatter.url},
                        {field: 'recorded_views', title: __('Recorded_views')},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'live_start', title: __('Live_start'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'live_end', title: __('Live_end'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'admin.id', title: __('Admin.id')},
                        //{field: 'admin.nickname', title: __('Admin.nickname')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [


                                {
                                    name: 'action',
                                    title: __('生成直播地址'),
                                    text: __('生成直播地址'),
                                    classname: 'btn btn-xs btn-primary margin  btn-dialog',
                                    icon: 'fa fa-life-buoy',
                                    url: 'live/build',
                                    // visible:function(res)
                                    // {
                                    //     if(res.live_url == '')
                                    //     {
                                    //         return true;
                                    //     }
                                    //     else
                                    //     {
                                    //         return false;
                                    //     }
                                    // },

                                },
                                {
                                    name: 'url',
                                    title: __('直播分享连接'),
                                    text: __('直播分享连接'),
                                    classname: 'btn btn-xs btn-success margin  btn-dialog',
                                    icon: 'fa  fa-link',
                                    url: 'live/url',
                                    // visible:function(res)
                                    // {
                                    //     if(res.live_url == '')
                                    //     {
                                    //         return true;
                                    //     }
                                    //     else
                                    //     {
                                    //         return false;
                                    //     }
                                    // },

                                },
                                {
                                    name: 'url',
                                    title: __('弹幕列表'),
                                    text: __('弹幕列表'),
                                    classname: 'btn btn-xs btn-info margin  btn-dialog',
                                    icon: 'fa  fa-comments',
                                    url: 'barrage/danmu',

                                },

                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});